fix: support ESLint 10 by using context.sourceCode property - #15
Merged
Conversation
ESLint 10 removed the deprecated `context.getSourceCode()` method, so `no-complex-conditionals` and `max-function-length` threw `TypeError: context.getSourceCode is not a function` when linting under ESLint 10. Add a `getSourceCode()` helper that prefers the `context.sourceCode` property and only falls back to the method when the property is absent, and use it in both rules. Adds regression tests that drive the rules with an ESLint 10 style context that has no `getSourceCode` method. Fixes #14 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GHzmaqnfUrfLno7pHBPeSq
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR adds ESLint 10 compatibility to the plugin by updating rules to use the
context.sourceCodeproperty instead of the deprecatedcontext.getSourceCode()method, which was removed in ESLint 10.A new helper function
getSourceCode()inutils/node-helpers.tsprovides backward compatibility by preferring the property and falling back to the method for older ESLint versions.Fixes #14
Type of change
How Has This Been Tested?
Added comprehensive regression tests in
tests/eslint10-compatibility.test.tsthat:sourceCodeproperty (nogetSourceCodemethod)no-complex-conditionalsrule works correctly withoutcontext.getSourceCode()max-function-lengthrule works correctly withoutcontext.getSourceCode()Both test cases confirm the rules properly report violations when using only the ESLint 10 API.
Checklist:
https://claude.ai/code/session_01GHzmaqnfUrfLno7pHBPeSq